<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap.css">

<script src="../Jquery/Jquery-3.3.1.js" type="text/javascript"></script>

<meta charset="UTF-8">
<title>添加新住宿生</title>
</head>
<body>
	<div style="text-align: center;">
		<form id="stud_form" style="margin-top: 20px;">
			<input type="text" id="studentNo" name="studentNo" maxlength="9" placeholder="请输入学号" class="inputclass"> <br>
			<br>
			<!--  -->
			<input type="text" id="studentName" name="studentName" maxlength="20" placeholder="请输入姓名" class="inputclass">
			<br> <br>
			<!--  -->
			<input type="text" id="buildingNo" name="buildingNo" maxlength="2" placeholder="请输入楼栋编号" class="inputclass">
			<br> <br>
			<!--  -->
			<input type="text" id="chamberNo" name="chamberNo" maxlength="4" placeholder="请输入寝室编号" class="inputclass"> <br>
			<br>
			<!--  -->
			<input type="button" value="确定" id="sub_commit" style="margin-right: 20px;">
			<!--  -->
			<input type="reset" value="重置" id="sub_reset" style="margin-left: 20px;">
		</form>
		<br> <br>
		<div>
			<a href="DormitoryManageSystem.html">返回系统导航页</a>
		</div>
	</div>
</body>

<script type="text/javascript">
	/* */
	$('#sub_commit').click(function() {
		/* RegExpression Validate */
		var studentNo = $('#studentNo').val();
		var studentName = $('#studentName').val();
		var buildingNo = $('#buildingNo').val();
		var chamberNo = $('#chamberNo').val();

		/*  */
		if (studentNo == '' || studentName == '' || buildingNo == '' || chamberNo == '') {
			alert("未填完");
			return;
		}

		//校验学号,由数字组成的字符串:/^[0-9]{1,}$/
		var expression = /^[0-9]{1,}$/;
		var exp = new RegExp(expression);
		if (exp.test(studentNo) == false) {
			alert("学号格式错误");
			return;
		}

		/*楼号格式校验,2位皆为数字*/
		var expression00 = /^\d{2}$/;
		var exp00 = new RegExp(expression00);
		if (exp00.test(buildingNo) == false) {
			alert('宿舍楼格式错误(请查看是否输入其他字符或长度不足)')
			return;
		}

		/*寝室号格式校验,4位皆为数字*/
		var expression01 = /^\d{4}$/;
		var exp01 = new RegExp(expression01);
		if (exp01.test(chamberNo) == false) {
			alert('寝室号格式错误(请查看是否输入其他字符或长度不足)');
			return;
		}

		var url = "/dormitory/Students/add_stud";
		var data = $("#stud_form").serialize();
		$.ajax({
			"url" : url,
			"data" : data,
			"type" : "POST",
			"dataType" : "json",
			"success" : function(json) {
				if (json.state == 200) {
					alert("登记成功");
					location.href = "DormitoryManageSystem.html";
				} else {
					alert(json.message);
				}
			}
		});
	});

	/* */
	$('#sub_reset').click(function() {
		$(".inputclass").val('')
	});
</script>
</html>